/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.tnmk.worktime.gui;

import java.util.List;
import org.tnmk.worktime.service.dao.entry.SpendEntry;
import org.tnmk.worktime.service.model.SessionModel;

/**
 *
 * @author tnmkhoi
 */
public class ControllerHelper {

  private static final ControllerHelper INSTANCE = new ControllerHelper();

  private ControllerHelper() {
  }

  public static ControllerHelper getInstance() {
    return INSTANCE;
  }

  public static void removeSpendInSessionViewModel(SessionModel viewModel, Integer spendId) {
    int found = findSpendInSessionViewModel(viewModel, spendId);
    if (found >= 0) {
      viewModel.getMoneySpend().removeAt(found);
    }
  }

  public static int findSpendInSessionViewModel(SessionModel viewModel, Integer spendId) {
    if (spendId == null) {
      return -1;
    }
    int i = 0;
    List<SpendEntry> spends = viewModel.getMoneySpend().getItems();
    for (SpendEntry spendEntry : spends) {
      if (spendId.equals(spendEntry.getId())) {
        return i;
      }
      i++;
    }
    return -1;
  }
}
